<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="/webjars/layui/2.5.7/css/layui.css"/>
</head>
<script src="/webjars/layui/2.5.7/layui.js"></script>
<body>
<form class="layui-form" >

    <div class="layui-form-item">
        <label class="layui-form-label">username</label>
        <div class="layui-input-block">
            <input type="text" name="username"  placeholder="请输入用户名" autocomplete="off" class="layui-input">
        </div>
    </div>


    <div class="layui-form-item">
        <label class="layui-form-label">单选框</label>
        <div class="layui-input-block">
            <input type="radio" name="sex" value="男" title="男">
            <input type="radio" name="sex" value="女" title="女" checked>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">password</label>
        <div class="layui-input-block">
            <input type="text" name="password"  placeholder="请输入密码" autocomplete="off" class="layui-input">
        </div>
    </div>


    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>

</body>



<script>
    //Demo
    layui.use(['form','jquery'], function(){
        var form = layui.form;
        var $ = layui.jquery;

        //监听提交
        form.on('submit(formDemo)', function(data){

            $.ajax({
                url:'/addStudentByUser',
                method:'post',
                data:JSON.stringify(data.field),
                dataType:'json',
                contentType:'application/json',
                success:function(data){
                        if(data == 1){
                            alert('添加成功')
                        }else{
                            alert('添加失败')
                        }
                },error:function(){
                            alert('与服务器交互失败')
                }
            })


            return false;
        });
    });
</script>
</html>